<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
			<button type="default" @click="send">点我发送</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {
			uni.connectSocket({
				url: 'ws://localhost:8085?2:3',
				success:()=>{
					console.log('connect success');
				}
			});

			uni.onSocketMessage(function(res) {
				console.log('收到服务器内容 other：' + res.data);
			});
		},
		methods: {
			send(){
				let service = {
					type: 'service',
					name: '沐兮',
					intro: '可爱如我 other',
					sex: '男',
					message: '厉害了',
					id:2
				}
				    uni.sendSocketMessage({
				      data: JSON.stringify(service),
					  success: (res) => {
					  	console.log(res,'other');
					  }
				    });
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
